package com.weichen.studentgameexchange.comment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.comment.entity.CommentLike;
import com.weichen.studentgameexchange.comment.entity.vo.AddLikeVo;
import com.weichen.studentgameexchange.comment.service.ICommentLikeService;
import com.weichen.studentgameexchange.common.common.Result;
import com.weichen.studentgameexchange.common.exception.ServiceException;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-05
 */
@RestController
@RequestMapping("/comment/commentLike")
public class CommentLikeController {

    @Autowired
    ICommentLikeService commentLikeService;

    /**
     * 用户点赞评论
     * @param addLikeVo
     * @return
     */
    @Operation(summary = "用户点赞评论")
    @PostMapping("/user/add")
    public Result userAdd(@RequestBody AddLikeVo addLikeVo){
        return commentLikeService.userAdd(addLikeVo);
    }

    /**
     * 用户查看点赞评论
     * @param commentId
     * @return
     */
    @Operation(summary = "用户查看点赞评论")
    @GetMapping ("/user/select/{commentId}")
    public Result userSelect(@PathVariable("commentId")  Long commentId){
        return commentLikeService.userSelect(commentId);
    }

    /**
     * 用户删除点赞评论
     * @param addLikeVo
     * @return
     */
    @Operation(summary = "用户删除点赞评论")
    @DeleteMapping("/user/delete")
    public Result userDelete(@RequestBody AddLikeVo addLikeVo){
        return commentLikeService.userDelete(addLikeVo);
    }

/**
 * TODO 管理员-评论管理--评论点赞
 */
    /**
     * 管理员分页查询评论信息
     *
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询评论信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size) {
        Page<CommentLike> commentLikePage = commentLikeService.adminPage(page, size);
        return Result.success(commentLikePage);
    }

    /**
     * 管理员删除单个评论点赞
     *
     * @param likeId
     * @return
     */
    @Operation(summary = "管理员删除单个评论点赞接口")
    @DeleteMapping("/admin/delete/{likeId}")
    public Result adminDeleteOne(@PathVariable("likeId") Long likeId) {
        if (commentLikeService.getById(likeId) == null)
            throw new ServiceException("点赞信息不存在！");
        commentLikeService.removeById(likeId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个评论点赞
     *
     * @return
     */
    @Operation(summary = "管理员批量删除多个评论点赞接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> likeIds) {
        likeIds.forEach(this::adminDeleteOne);
        return Result.success();
    }
}
